#! /bin/bash -e

# check if pwd is src directory

if [ "$(basename `pwd`)" != "src" ]; then echo "install.sh must be executed in src path"; exit 1; fi


mkdir -p ../lib
mkdir -p ../etc/lcm
mkdir -p ../bin
mkdir -p ../sbin

cd liblcm
make all
mv liblcm.so ../../lib/liblcm.so
make clean
cd ..

cd lcm
make all
mv lcm ../../bin
cat > ../../etc/lcm/lcm.conf << EOF
core::configdir=/etc/lcm

net::ip=127.0.0.1
net::port=1508

log::file=/var/log/lcm/lcm.log
log::level=debug
EOF

make clean

cd ..

cd lcmd
make all
mv lcmd ../../sbin/lcmd
cat > ../../etc/lcm/lcmd.conf << EOF
#  Configuration file for lcmd


# core part

# sets configuration directory where lcmd searchs for lcmd.conf (default: /etc/lcm)
core::configdir = /etc/lcm

# sets lockfile, if it exists then lcmd won't start (default: /var/lock/lcmd.lock)
core::lockfile = /var/lock/lcmd.lock

# sets pidfile (default: /var/run/lcmd.pid)
core::pidfile = /var/run/lcmd.pid

# should lcmd start in daemon mode? (default: yes)
core::daemonize = no

# send script even if the md5 hash is wrong
core::sendonmd5mismatch = yes

# net part

# sets port where lcmd should listen on
net::port = 1508

# sets interface where lcmd should  listen on
net::ip = 127.0.0.1


# logging part

# sets logfile for lcmd (default: /var/log/lcm/lcmd.log)
log::file = /var/log/lcm/lcmd.log # not implemented yet

# sets loglevel for lcmd (default: debug)
# this only specifies the amount of output for the logfile,
# if you want to specify the amount of output for the terminal
# use -v option on the command line
log::level = debug # not implemented yet


# mysql part

# sets database name for mysql use (default: lcm)
mysql::db = lcm

# sets mysql server (default: 127.0.0.1)
mysql::server = 127.0.0.1

# sets mysql port (default: 3306)
mysql::port = 3306

# sets mysql user (default lcmd)
mysql::user = lcmd

# sets mysql password for user specified above (default: lcmd)
mysql::pass = lcmd
EOF

make clean
cd ..